﻿@model DormMS.Model.Member
@{
    DormMS.Model.Order order = ViewBag.order;
}
<style>
    .ts_txt{font-size: 12px;color:red;margin-bottom: 10px;}
</style>

<div>
    <div class="flayout_a_box">
        <div class="flayout_a_row">
            <span>订单总额</span>
            <label class="flayout_a_row_right">¥@ViewBag.order.OrderPrice</label> @*{{Order.OrderPrice}}*@
        </div>
        @if (Model.Balance > 0&& order.MemberMoney==0&&order.OrderType!=DormMS.Model.Enum.OrderType.一分钱订单)
        {
            <div class="f_jfdy">
                <span>使用余额(当前：@Model.Balance)</span>
                <div class="right">
                    <label id="money" class="notUse" onclick="use()"></label>
                </div>
            </div>
        }
        <div class="flayout_a_row border_bottom0">
            <span>实付款</span>
            <label class="flayout_a_row_right red lala">¥@ViewBag.order.PayMoney</label> @*{{Order.PayMoney}}*@
        </div>
    </div>
    <div class="flayout_a_box">
        <div class="flayout_a_row border_bottom0">
            <span class="flayout_a_row_left gray">支付方式</span>
            <label class="flayout_a_row_right">微信支付</label>
        </div>
    </div>
    <div class="ts_txt">如果30分钟内未支付订单，订单将会被自动取消</div>
    <!-- 底部的付款 -->
    <div class="flayout_a_bottomBtnbox">
        <div class="flayout_a_bottomBtnbox_left">
            <span>实付款：</span>
            <label class="lala">¥@ViewBag.order.PayMoney</label> @*{{Order.PayMoney}}*@
        </div>
        <input type="button" id="pay"  onclick="pay()" value="付款" class="flayout_a_bottomBtnbox_right" />
    </div>
</div>
<script>
    // 当微信内置浏览器完成内部初始化后会触发WeixinJSBridgeReady事件。
    document.addEventListener('WeixinJSBridgeReady', function onBridgeReady() {
        //公众号支付



    }, false);
    var orderId =@ViewBag.orderId

    function use()
    {
        $("#money").toggleClass("Use");
        var isuse = false;
        if ($("#money").hasClass("Use")) {
            isuse = true;
        }
        layer.load(2);
        $.ajax({
            url: "/OrderPayment/Use",
            type: "POST",
            dataType: "json",
            async: true,
            data: { totalpay: "@ViewBag.order.PayMoney", isUseBalance: isuse },
            success: function (response) {
                layer.closeAll('loading');
                if (response.isSuccess) {
                    var paymoney = response.data;
                    $(".lala").html('¥' + paymoney);
                }
                else
                {
                    layer.msg(response.data.msg);
                }
            },
            error: function (data) {
                layer.closeAll('loading');
                layer.msg("系统错误！");
            }
        })
    }
    function pay() {
        layer.load(2);
        var isuse = false;
        if ($("#money").hasClass("Use"))
        {
            isuse = true;
        }
        $.ajax({
            url: "/OrderPayment/ToPay",
            type: "POST",
            dataType: "json",
            async: true,
            data: { orderId: orderId, isUseBalance:isuse },
            success: function (response) {
                layer.closeAll('loading');
                if (response.isSuccess) {

                    var Order = response.model;
                    if (Order.PayState == 1) {
                        if (Order.OrderType == 4 || Order.OrderType == 2) {
                            //$state.go('shop.actsuccess', { id: Order.Id });
                            window.location.href = "http://wx.youpinsanyue.com/#/shop/actsuccess?id=" + Order.Id;
                        }
                        else {
                            //$state.go('shop.success');
                            window.location.href = "http://wx.youpinsanyue.com/#/shop/success";
                        }
                    }
                    else {

                        var Model = response.data;

                        WeixinJSBridge.invoke('getBrandWCPayRequest', {
                            "appId": Model.appId, //公众号名称，由商户传入
                            "timeStamp": Model.timeStamp, //时间戳
                            "nonceStr": Model.nonceStr, //随机串
                            "package": Model.package,//扩展包
                            "signType": "MD5", //微信签名方式:MD5
                            "paySign": Model.paySign //微信签名
                        }, function (res) {
                            if (res.err_msg == "get_brand_wcpay_request:ok") {
                                if (Order.OrderType == 4 || Order.OrderType == 2) {
                                    //$state.go('shop.actsuccess', { id: Order.Id });
                                    window.location.href = "http://wx.youpinsanyue.com/#/shop/actsuccess?id=" + Order.Id;
                                }
                                else {
                                    //$state.go('shop.success');
                                    window.location.href = "http://wx.youpinsanyue.com/#/shop/success";
                                }
                            }
                            else {

                            }

                        });
                    }
                }
                else {
                    layer.msg(response.data.msg);
                }
            },
            error: function (data) {
                layer.closeAll('loading');
                layer.msg("系统错误！");
            }
        })
    }

    //App.controller('OrderPayController', [
    //        '$scope', '$state', '$route', '$http', '$stateParams',
    //            function ($scope, $state, $route, $http, $stateParams) {
    //                layer.load(2);
    //                $http.post("/OrderPayment/GetOrderPay", { orderid: $stateParams.id }).then(function (response) {
    //                    layer.closeAll('loading');
    //                    if (response.data.isSuccess) {
    //                        //$scope.Model = angular.copy(response.data.data);
    //                        $scope.Order = angular.copy(response.data.model);
    //                    }
    //                    else {
    //                        layer.msg(response.data.msg);
    //                    }
    //                });


    //                $scope.pay = function () {


    //                    layer.load(2);
    //                    $http.post("/OrderPayment/ToPay", { orderId: $stateParams.id }).then(function (response) {
    //                        layer.closeAll('loading');
    //                        if (response.data.isSuccess) {
    //                            $scope.Model = angular.copy(response.data.data);
    //                            //$scope.Order = angular.copy(response.data.model);

    //                            WeixinJSBridge.invoke('getBrandWCPayRequest', {
    //                                "appId": $scope.Model.appId, //公众号名称，由商户传入
    //                                "timeStamp": $scope.Model.timeStamp, //时间戳
    //                                "nonceStr": $scope.Model.nonceStr, //随机串
    //                                "package": $scope.Model.package,//扩展包
    //                                "signType": "MD5", //微信签名方式:MD5
    //                                "paySign": $scope.Model.paySign //微信签名
    //                            }, function (res) {
    //                                if (res.err_msg == "get_brand_wcpay_request:ok") {

    //                                    if ($scope.Order.OrderType == 4 || $scope.Order.OrderType == 2) {
    //                                        $state.go('shop.actsuccess', { id: $scope.Order.Id });
    //                                    }
    //                                    else {
    //                                        $state.go('shop.success');
    //                                    }
    //                                }
    //                                else {

    //                                }

    //                            });
    //                        }
    //                        else {
    //                            layer.msg(response.data.msg);
    //                        }
    //                    });


    //            }
    //}
    //]);
</script>